//根目录  http://api-breakingnews-web.itheima.net 
axios.defaults.baseURL = " http://api-breakingnews-web.itheima.net"


//请求拦截器 
axios.interceptors.request.use(config => {

  // Do something before request is sent
  // console.log(config)
  // console.log(config.url)

  if (config.url.includes('/my')) {

    //或者是if（config.url.indexOf（'/my'）输出true false）

    config.headers.Authorization = localStorage.getItem('token')
  }


  return config //必须要待着这行 ，否则请求都发不出去
}, error => {

  // Do something with request error

  return Promise.reject(error);

});



//响应拦截器

axios.interceptors.response.use(response => {
  // Do something before response is sent
  // console.log(response)

  //判断用户的登录权限
  if (response.data.status === 1 && response.data.message === "身份认证失败！") {
    console.log(1);
    location.href = '/login.html'
  }


  return response;
}, error => {
  // Do something with response error
  return Promise.reject(error);
})
